package com.cooper.tld;

import javax.servlet.jsp.JspException;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import com.google.common.io.Files;

/**
 * 
 * @Description: <br>
 * @Date: Jan 27, 2014 9:21:40 PM<br>
 * @Copyright (c) 2014 MiXuan <br> * 
 * @since 1.0
 * @author coral
 */
public class ImageResizableTag extends CoralBaseTag {
	private static final long serialVersionUID = -5764554683990511492L;
	private String value = null;
	private int width = 0;
	private int height = 0;
	
	@Override
	public int doStartTag() throws JspException {
		StringBuffer buffer = new StringBuffer();
		
		String extension = Files.getFileExtension(value);
		String fileName = value.substring(0, value.length() - extension.length());
		int pos = fileName.lastIndexOf('_');
		if(pos > 0){
			fileName = fileName.substring(0, pos+1);
		}
		buffer.append(fileName).append(this.width).append(".").append(extension);
		this.write(buffer.toString());
		return super.doStartTag();
	}
	
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) throws JspException {
		this.value = ExpressionEvaluatorManager.evaluate("value", value, 
				String.class, this, pageContext).toString();
	}
	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}

}

